<?php

/**
 * Object used to manage customers and their information
 * 
 * @package Customer
 * @author Guillem Mateos
 * @version 0.1
 * @abstract 
 * @copyright GRITO2003, S.L.
 */

/**
 * includes
 */
//include_once( '../library/config.php' );
include_once( FROG_DATABASE.'DBObject.class.php' );

class Karma extends DBObject
{
  /**
  * Initialize vars
  */
  public function initVars( )
  {
    $this->dbfields['id_karma'] = null;
    $this->dbfields['id_user_from'] = null;
    $this->dbfields['id_user_to'] = null;
    $this->dbfields['id_product'] = null;
    $this->dbfields['name'] = null;
    $this->dbfields['points'] = null;
    
    $this->dbparams['table'][0] = 'karma';
    $this->dbparams['main_id'] = 'id_karma';
  }
  
  public static function findById_user( $id )
  {
    if( !$id )
      return false;
      
    $c = new Karma();
        
    $w_expr_01 = new Expression( 'id_user_from', '=', $id );

    $result = $c->select( '', $w_expr_01  );
    
    return $result[0];
  }
  
  public static function findPoints( $id )
  {
  	if( !$id )
      return false;
      
    $c = new Karma();
        
    $w_expr_01 = new Expression( 'id_user_from', '=', $id );

    $result = $c->select( array( 'SUM( points ) AS points' ), $w_expr_01  );
    
    return $result[0]->getPoints();
  }
} 

?>